package com.liu.seckill.config;


import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;


/**
 * @ClassName RabbitMQConfig
 * @Author ：name
 * @Date ：2022-02-18 10:18
 * @Description：
 * @Version: 1.0
 */
@Configuration
public class RabbitMQConfig {

    private static final String QUEUE01 = "queue_fanout01";
  private static final String QUEUE02 = "queue_fanout02";
  private static final String EXCHANGE = "fanoutExchange";
    private static final String QUEUE03 = "queue_direct01";
    private static final String QUEUE04 = "queue_direct02";
    private static final String EXCHANGE02 = "directExchange";
    private static final String ROUTINGKEY01 = "queue.red";
    private static final String ROUTINGKEY02 = "queue.green";

    private static final String QUEUE05 = "queue_topic01";
    private static final String QUEUE06 = "queue_topic02";
    private static final String EXCHANGE03 = "topicExchange";
    private static final String ROUTINGKEY03 = "#.queue.#";
    private static final String ROUTINGKEY04 = "*.queue.#";

    private static final String QUEUE07 = "queue_header01";
    private static final String QUEUE08 = "queue_header02";
    private static final String EXCHANGE05 = "headersExchange";


    @Bean
  public Queue queue01(){
   return new Queue(QUEUE01);
  }
  @Bean
  public Queue queue02(){
   return new Queue(QUEUE02);
  }

  @Bean
  public Queue queue03(){
        return new Queue(QUEUE03);
  }
    @Bean
    public Queue queue04(){
        return new Queue(QUEUE04);
    }

    @Bean
    public Queue queue05(){
        return new Queue(QUEUE05);
    }

    @Bean
    public Queue queue06(){
        return new Queue(QUEUE06);
    }


    @Bean
    public Queue queue07(){
        return new Queue(QUEUE07);
    }

    @Bean
    public Queue queue08(){
        return new Queue(QUEUE08);
    }

  @Bean
  public FanoutExchange fanoutExchange(){
   return new FanoutExchange(EXCHANGE);
  }
  @Bean
  public Binding binding01(){


   return BindingBuilder.bind(queue01()).to(fanoutExchange());
  }



  @Bean
  public Binding binding02(){
   return BindingBuilder.bind(queue02()).to(fanoutExchange());
  }

    @Bean
    public DirectExchange directExchange(){

        return new DirectExchange(EXCHANGE02);

    }

    @Bean
    public Binding binding03(){
        return  BindingBuilder.bind(queue03()).to(directExchange()).with(ROUTINGKEY01);
}

    @Bean
    public Binding binding04(){
        return BindingBuilder.bind(queue04()).to(directExchange()).with(ROUTINGKEY02);
    }


    @Bean
    public TopicExchange topicExchange(){

        return new TopicExchange(EXCHANGE03);

    }

    @Bean
    public Binding binding05(){
        return
                BindingBuilder.bind(queue05()).to(topicExchange()).with(ROUTINGKEY03);
    }
    @Bean
    public Binding binding06(){
        return
                BindingBuilder.bind(queue05()).to(topicExchange()).with(ROUTINGKEY04);
    }


    @Bean
    public HeadersExchange headersExchange(){
        return new HeadersExchange(EXCHANGE05);
    }

    @Bean
    public Binding binding07(){
        HashMap<String, Object> map = new HashMap<>();
        map.put("color","reda");
        map.put("speed","low");
        return BindingBuilder.bind(queue07()).to(headersExchange()).whereAny(map).match();
    }

    @Bean
    public Binding binding08(){
        HashMap<String, Object> map = new HashMap<>();
        map.put("color","red");
        map.put("speed","fast");
        return BindingBuilder.bind(queue08()).to(headersExchange()).whereAll(map).match();
    }

    private static final String QUEUE09 = "seckillQueue";
     private static final String EXCHANGE09 = "seckillExchange";
    @Bean
  public Queue queue09(){
   return new Queue(QUEUE09);
  }

    @Bean
  public TopicExchange topicExchange09(){
   return new TopicExchange(EXCHANGE09);
  }

    @Bean
  public Binding binding09(){

        return BindingBuilder.bind(queue09()).to(topicExchange09()).with("seckill.#");

    }



}
